//
//  CZPictureWallViewController.m
//  QQ空间
//
//  Created by zhangping on 16/1/16.
//  Copyright © 2016年 zhangping. All rights reserved.
//

#import "CZPictureWallViewController.h"
#import "UIBarButtonItem+Extension.h"
#import "CZTopItem.h"
#import "CZCategoryViewController.h"

@interface CZPictureWallViewController ()

@property(nonatomic, strong) UIBarButtonItem *categoryItem;

@property(nonatomic, strong) UIBarButtonItem *regionItem;

@end

@implementation CZPictureWallViewController 

static NSString * const reuseIdentifier = @"Cell";

- (instancetype)init {
    if (self = [super initWithCollectionViewLayout:[[UICollectionViewFlowLayout alloc] init]]) {
        
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
    [self setupLeftNav];
    [self setupRightNav];
}

/// 设置导航栏左边
- (void)setupLeftNav {
    CZTopItem *categoryTopItem = [CZTopItem topItemWithIcon:@"icon_district" title:@"主标题" subTitle:@"子标题"];
    UIBarButtonItem *categoryItem = [[UIBarButtonItem alloc] initWithCustomView:categoryTopItem];
    self.navigationItem.leftBarButtonItem = categoryItem;
    [categoryTopItem addTarget:self action:@selector(categoryTopItemClick)];
    self.categoryItem = categoryItem;
    
    CZTopItem *regionTopItem = [CZTopItem topItemWithIcon:@"icon_district" title:@"主标题" subTitle:@"子标题"];
    UIBarButtonItem *regionItem = [[UIBarButtonItem alloc] initWithCustomView:regionTopItem];
    self.navigationItem.leftBarButtonItems = @[categoryItem, regionItem];
    [regionTopItem addTarget:self action:@selector(regionTopItemClick)];
    self.regionItem = regionItem;
}

/// 设置右边导航栏
- (void)setupRightNav {
    UIBarButtonItem *mapItem = [UIBarButtonItem itemWithImageName:@"icon_map"];
    UIBarButtonItem *searchItem = [UIBarButtonItem itemWithImageName:@"icon_search"];
    
    self.navigationItem.rightBarButtonItems = @[mapItem, searchItem];
    
    mapItem.customView.width = 60;
    searchItem.customView.width = 60;
}

#pragma mark - 按钮点击代理
- (void)categoryTopItemClick {
    CZLog(@"categoryTopItemClick");
    
    CZCategoryViewController *categoryVC = [[CZCategoryViewController alloc] init];
    
    UIPopoverController *categoryPopover = [[UIPopoverController alloc] initWithContentViewController:categoryVC];
    
    [categoryPopover presentPopoverFromBarButtonItem:self.categoryItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

- (void)regionTopItemClick {
    CZLog(@"regionTopItemClick");
}
@end
